(() => {
  let ele = {};
  ele.listBox = $("#listBox");
  let list = [];
  asyncList();
  function asyncList() {
    let token = getCookie("token");
    ajax({
      method: "get",
      url: API_PATH.SHANGQI,
      header: {
        Authorization: token,
      },

      success: (res) => {
        list = res.data;
        initList();
      },
      error: (err) => {
        // openTips(err.msg);
      },
    });
  }
  // !渲染数据
  function initList() {
    let newList = list
      .map((item, index) => {
        return `  <div class="list">
      <div class="left">
        <div class="leftin">
          <img src="${
            item[0].info && item[0].info.head_pic
              ? IMG_DOMAIN + item[0].info.head_pic
              : item[0].info.sex == 1
              ? "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx1.png"
              : "http://img.qxgs.cc/tiantianlaishouzu/img/my/tx2.png"
          }" alt="" />
          <span class="fang1" id="fang" data-type="${
            item[0].type
          }" data-h_id="${item[0].h_id}">房东</span>
        </div>
        <p>${
          item[0].info && item[0].info.nick_name
            ? item[0].info.nick_name
            : "微风"
        }</p>
      </div>
      <div class="right" id="box_wai" data-num="${index + 1}">
        <div class="thingin thingcoffee">
          <img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/6.png" alt="" />
          <span>x${item.get_money}</span>
        </div>
        <div data-type="${item.type}" data-h_id="${
          item.h_id
        }" id="baoxiang" data-in="${item.is_j}" class="thingin thingpurple">
             <img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/8.png" alt="" />
        <span>房东宝箱</span>
      </div>
      </div>
    </div>`;
      })
      .join(" ");
    ele.listBox.innerHTML = newList;
    if (list.length == 0) {
      ele.listBox.innerHTML = `<div class="center_wu">暂无记录<div/>`;
    }
    let fangAll = document.querySelectorAll("#fang");
    fangAll.forEach((item) => {
      if (item.dataset.h_id == 2 && item.dataset.type == 1) {
        item.classList.add("fang3");
        item.classList.remove("fang");
        item.innerHTML = "楼主";
      } else {
        if (item.dataset.type == 1) {
          item.classList.add("fang1");
          item.classList.remove("fang");
          item.classList.remove("fang2");
          item.classList.remove("fang3");
          item.innerHTML = "房东";
        } else if (item.dataset.type == 3) {
          item.classList.add("fang2");
          item.classList.remove("fang");
          item.classList.remove("fang1");
          item.classList.remove("fang3");
          item.innerHTML = "管家";
        } else if (item.dataset.type == 2) {
          item.classList.add("fang2");
          item.classList.remove("fang");
          item.classList.remove("fang1");
          item.classList.remove("fang3");
          item.innerHTML = "租客";
        }
      }
    });
    // !宝箱
    let box_waiAll = document.querySelectorAll("#box_wai");
    box_waiAll.forEach((item, index) => {
      if (item.dataset.num == index + 1) {
        let new1 = list[index]
          .map((ite) => {
            return `
          <div class="thingin ${
            ite.bx_type == 0 ? "thingcoffee" : "thingorange"
          }">
          <img style="display:${
            ite.bx_type == 0 ? "block" : "none"
          };" src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/6.png" alt="" />
          <img style="display:${
            ite.bx_type == 1 ? "block" : "none"
          };" src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/7.png" alt="" />
          <img style="display:${
            ite.bx_type == 2 ? "block" : "none"
          };" src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/8.png" alt="" />
          <img style="display:${
            ite.bx_type == 3 ? "block" : "none"
          };" src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/9.png" alt="" />
          <img style="display:${
            ite.bx_type == 4 ? "block" : "none"
          };" src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/9.png" alt="" />
          <span style="display:${ite.bx_type == 0 ? "block" : "none"};">x${
              ite.get_money
            }</span>
          <span style="display:${
            ite.bx_type == 1 ? "block" : "none"
          };">楼主宝箱</span>
          <span style="display:${
            ite.bx_type == 2 ? "block" : "none"
          };">管家宝箱</span>
          <span style="display:${
            ite.bx_type == 3 ? "block" : "none"
          };">直管宝箱</span>
          <span style="display:${
            ite.bx_type == 4 ? "block" : "none"
          };">间管宝箱</span>
       
        </div> 
         `;
          })
          .join(" ");
        item.innerHTML = new1;
      }
    });
    // let baoxiangAll = document.querySelectorAll("#baoxiang");
    // baoxiangAll.forEach((item) => {
    //   if (item.dataset.type == 2) {
    //     // 没宝箱
    //     closeMdl(item);
    //   } else {
    //     if (item.dataset.h_id == 2 && item.dataset.type == 1) {
    //       // 说明是楼主
    //       item.style.backgroundImage = "url(http://img.qxgs.cc/tiantianlaishouzu/img/reward/2.png)";
    //       item.innerHTML = `<img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/7.png" alt="" />
    // <span>楼主宝箱</span>`;
    //     } else {
    //       if (item.dataset.type == 1 && item.dataset.in == 1) {
    //         item.style.backgroundImage = "url(http://img.qxgs.cc/tiantianlaishouzu/img/reward/1.png)";
    //         item.innerHTML = `<img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/9.png" alt="" />
    //   <span>直管宝箱</span>`;
    //       } else if (item.dataset.type == 3) {
    //         item.style.backgroundImage = "url(http://img.qxgs.cc/tiantianlaishouzu/img/reward/3.png)";
    //         item.innerHTML = `<img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/8.png" alt="" />
    //   <span>管家宝箱</span>`;
    //       } else if (item.dataset.type == 1 && item.dataset.in == 0) {
    //         item.style.backgroundImage = "url(http://img.qxgs.cc/tiantianlaishouzu/img/reward/3.png)";
    //         item.innerHTML = `<img src="http://img.qxgs.cc/tiantianlaishouzu/img/reward/9.png" alt="" />
    //   <span>间管宝箱</span>`;
    //       }
    //     }
    //   }
    // });
  }
})();
